package com.lx;

import com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportResource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Arrays;

import static com.lx.Start.*;
import static org.hibernate.validator.internal.util.Contracts.assertNotNull;

/**
 * Created by lanyxp on 2021/2/23 10:24
 * <br> 项目启动入口</br>
 */
@Slf4j
@EnableSwagger2
@EnableDubboConfig
@SpringBootApplication(scanBasePackages = {LCN_BASE_SCAN_PACKAGE, PROJECT_BASE_SCAN_PACKAGE,
        DUBBO_PROVIDE_ORDER_SCAN_PACKAGE, DUBBO_PROVIDE_ORDER_SCAN_PACKAGE2})
@EnableTransactionManagement(proxyTargetClass = true)
@DubboComponentScan(basePackages = {DUBBO_BASE_SCAN_PACKAGE})
@ImportResource(locations = {DUBBO_LOCAL_FILE_PATH})
@MapperScan(basePackages = {MYBATIS_BASE_SCAN_PACKAGE})
public class Start extends SpringBootServletInitializer {

    public static final String DUBBO_BASE_SCAN_PACKAGE = "com.lx.app.impl.*";
    public static final String MYBATIS_BASE_SCAN_PACKAGE = "com.lx.dal.mapper";
    public static final String LCN_BASE_SCAN_PACKAGE = "com.codingapi.tx.*";
    public static final String PROJECT_BASE_SCAN_PACKAGE = "com.lx.*";
    public static final String DUBBO_PROVIDE_ORDER_SCAN_PACKAGE = "com.lx.demo.service";
    public static final String DUBBO_PROVIDE_ORDER_SCAN_PACKAGE2 = "com.lx.demo.b.service";
    public static final String DUBBO_LOCAL_FILE_PATH = "classpath:dubbo.xml";

    public static void main(String[] args) {
        SpringApplication.run(Start.class, args);
        log.info("启动成功");
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Start.class);
    }
}
